package cn.dinghu.pro.service.impl;

import cn.dinghu.pro.common.ResultData;
import cn.dinghu.pro.entity.Nurse;
import cn.dinghu.pro.entity.Orders;
import cn.dinghu.pro.entity.User;
import cn.dinghu.pro.mapper.NurseMapper;
import cn.dinghu.pro.service.INurseService;
import cn.dinghu.pro.utils.Pager;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 护工表 服务实现类
 * </p>
 *
 * @author dinghu
 * @since 2025-10-14
 */
@Service
public class NurseServiceImpl extends ServiceImpl<NurseMapper, Nurse> implements INurseService {
    @Autowired
    private NurseMapper nurseMapper;
    @Override
    public int edit(Nurse nurse) {
        return nurseMapper.update(nurse);
    }

    @Override
    public int add(Nurse nurse) {
        return nurseMapper.addAll(nurse);
    }

    @Override
    public ResultData updateStatus(int status, int id) {
        return nurseMapper.updateStatus(status,id)>0?ResultData.ok_201():ResultData.fail_201();
    }

    @Override
    public Nurse login(String username, String password) {
        Nurse nurse = null;
        try {
            nurse = nurseMapper.doLogin(username,password);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return nurse;
    }

    @Override
    public List<Orders> getAppInfoList(String realName, String status, Integer pageNo, Integer pageSize) {
        return nurseMapper.getAppInfoList(realName,status,(pageNo-1)*pageSize,pageSize);
    }

    @Override
    public int getAppInfoCount(String realName, String status) {
        return nurseMapper.getAppInfoCount(realName,status);
    }

    @Override
    public ResultData getPageInfo(String realName, String status, Integer pageNo, Integer pageSize) {
        Pager<Orders> pager=new Pager<>();
        pager.setPageNo(pageNo);
        pager.setPageSize(pageSize);
        pager.setTotalCount(this.getAppInfoCount(realName,status));
        pager.setDataList(this.getAppInfoList(realName,status,pageNo,pageSize));

        if (pager.getDataList().size()>0){
            return ResultData.ok(pager);
        }else {
            return ResultData.noData();
        }
    }

    @Override
    public int getCountPj(Integer good, Integer bad, Integer goodbad, Integer nuserId) {
        return nurseMapper.getCountPj(good,bad,goodbad,nuserId);
    }
}
